import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;
import java.util.Scanner;


/********************
 *	PB AVEC STATIC	*
 ********************/

public class Client {
	
	private static String buffer0 = "127.0.0.1";
	
	public static String getBuffer0() {
		return buffer0;
	}
	
	public static void main(String[] zero){
		
		Socket socket;
		BufferedReader in;
		PrintWriter out;
		Scanner sc = new Scanner(System.in);
		int fin = 1, choix = 0;
		
		while (fin == 1) {
			
			System.out.println("Pour continuer, taper 1. Pour terminer, taper 0");
//			Scanner sc = new Scanner(System.in);
			fin = sc.nextInt();
			
			System.out.println("Saisissez le type de la requete a envoyer au serveur :\n 0- Rien\n" +
					" 1- Reponse a un message de coupe\n 2- Reponse a un message de prise de decision (oui/non)\n" +
					" 3- Reponse a un message de prise de decision (pique/coeur/carreaux/trefle)\n" +
					" 4- Message pour jouer une carte\n 5- Demande de score");
//			Scanner scan = new Scanner(System.in);
			choix = sc.nextInt();
			
			try {
				socket = new Socket(buffer0,2009);
				in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				String message_distant = in.readLine();
				System.out.println(message_distant);
				out = new PrintWriter(socket.getOutputStream());
				out.println(requete(choix));
				out.flush();
				socket.close();
			}
			catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static String requete(int type_requete) {
//		String buffer0 = "IP";
		String buffer1 = "PORT";
		String buffer2 = "REPONSE COUPE";
		String buffer3 = "REPONSE DECISION";
		String buffer4 = "REPONSE DECISION - CHOIX";
		String buffer5 = "REPONSE JOUER-CARTE";
		String buffer6 = "REPONSE SCORE TEMPORAIRE";
//		String buffer7 = "REPONSE SCORE DEFINITIF";
			
		String requete = new String();
		switch (type_requete) {
			case 1:		// Distribution, demande de coupe
				requete = "ENSIBELOTE "+getBuffer0()+" "+buffer1+" "+buffer2;
				break;
			case 2:		// Demande prise de decision
				requete = "ENSIBELOTE "+getBuffer0()+" "+buffer1+" "+buffer3;
				break;
			case 3:		// Demande prise de decision proposition
				requete = "ENSIBELOTE "+getBuffer0()+" "+buffer1+" "+buffer4;				
				break;
			case 4:		// Jouer carte
				requete = "ENSIBELOTE "+getBuffer0()+" "+buffer1+" "+buffer5;
				break;
			case 5:		// Affichage score
				requete = "ENSIBELOTE "+getBuffer0()+" "+buffer1+" "+buffer6;
				break;
			default:	// RIEN
				requete = "ENSIBELOTE null";
				break;
		}
		return requete;
	}
}
